<?php 


require "../common/Curl.php";

/**
 *	https=>//open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	签署流程API----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 签署文档 sign2.php
 */



//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [createSignFlows 签署流程创建]
 * @param  [type] $aaaa   [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function createSignFlows($aaaa,$appId,$secret,$url){
	$urlss = $url."/v1/signflows";
	$head_url = "/v1/signflows";
    $data = json_decode($aaaa,true);
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}

// $aaaa = '{
//     "autoArchive":false,
//     "businessScene":"合同名称",
//     "configInfo":{
//         "noticeDeveloperUrl":"http://127.0.0.1:9110/notice",
//         "noticeType":"1,2",
//         "redirectUrl":"http://127.0.0.1:8110/h5/forword",
//         "signPlatform":"1",
//         "willTypes":["FACE_ZHIMA_XY"],
//         "personAvailableAuthTypes":["PSN_FACEAUTH_BYURL"],
//         "batchDropSeal":true,
//         "orgAvailableAuthTypes":["ORG_BANK_TRANSFER"],
//         "personAuthAdvancedEnabled":["PSN_BANK4_AUTHCODE"],
//         "countdown":5
//     },
//     "contractRemind":360,
//     "contractValidity":1592386042000,
//     "signValidity":1592386042000,
//     "initiatorAccountId":"5539bd029e4e45f4b2095aacbcf1ea19",
//     "initiatorAuthorizedAccountId":"6f69dc0a5c8d415aa6a0c7e239a32241"
// }';

// $a = createSignFlows($aaaa,$appId,$secret,$url);
// var_dump($a);die;  //9a1f67f7f8094d5bbe24ff6927ba4e03

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [selectSignFlows 签署流程查询]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function selectSignFlows($flowId,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId;
	$head_url = "/v1/signflows/".$flowId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $a = selectSignFlows($flowId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [startSignFlows 签署流程开启]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function startSignFlows($flowId,$appId,$secret,$url){
    $urlss = $url."/v1/signflows/".$flowId."/start";
    $head_url = "/v1/signflows/".$flowId."/start";
	$data =[
		"flowId"=>$flowId
	];
    $res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $a = startSignFlows($flowId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [endSignFlows 签署流程撤销]
 * @param  [type] $flowId       [description]
 * @param  [type] $operatorId   [description]
 * @param  [type] $revokeReason [description]
 * @param  [type] $appId        [description]
 * @param  [type] $secret       [description]
 * @param  [type] $url          [description]
 * @return [type]               [description]
 */
function endSignFlows($flowId,$operatorId,$revokeReason,$appId,$secret,$url){
    $urlss = $url."/v1/signflows/".$flowId."/revoke";
    $head_url = "/v1/signflows/".$flowId."/revoke";
	$data =[
		"flowId"=>$flowId,
		"operatorId"=>$operatorId,
		"revokeReason"=>$revokeReason
	];
    $res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $operatorId = "5539bd029e4e45f4b2095aacbcf1ea19";
// $revokeReason = "没有合作的意向";
// $a = endSignFlows($flowId,$operatorId,$revokeReason,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [archiveSignFlows 签署流程归档]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function archiveSignFlows($flowId,$appId,$secret,$url){
    $urlss = $url."/v1/signflows/".$flowId."/archive";
    $head_url = "/v1/signflows/".$flowId."/archive";
	$data =[
		"flowId"=>$flowId
	];
    $res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $a = archiveSignFlows($flowId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [archiveListSignFlows 归档分类]
 * @param  [type] $aaaa   [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function archiveListSignFlows($aaaa,$appId,$secret,$url){
	$urlss = $url."/v2/open/grouping_files/grouping";
	$head_url = "/v2/open/grouping_files/grouping";
    $data = json_decode($aaaa,true);
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $aaaa = '{
//     "menuId": "45632d6ff80123453dd000559ea148",
//     "flowIdList": [
//         "123bb231f234523488d2b0e7c58e0be6",
//         "001edb2ef36a491894c3056620da6057"
//     ]
// }';
// $a = archiveListSignFlows($aaaa,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [getVoucher 数据存储凭据]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function getVoucher($flowId,$appId,$secret,$url){
	$urlss = $url."/api/v2/signflows/".$flowId."/getVoucher";
	$head_url = "/api/v2/signflows/".$flowId."/getVoucher";
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $a = getVoucher($flowId,$appId,$secret,$url);
// var_dump($a);die;


